package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IProductService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/products")
public class ProductController {
    @Autowired
    private IProductService productService;


    /*
     *根据名字查询
     * 资源:/products/byName
     * 动作:GET
     * 参数:currentPage=x
     **/
    @GetMapping("/byName")
    public Object GetByName(QueryObject qo){
        PageInfo result = productService.query(qo);
        return result;
    }


    /*
     *查询所有,批量查询
     * 资源:/products/money
     * 动作:GET
     * 参数:currentPage=x
     **/
    @GetMapping("/money")
    public Object GetProductBymoney(){
        return productService.selectByMoney();
    }




    /*
     *查询很贵的超过商品内容超过90000,批量查询
     * 资源:/products/money
     * 动作:GET
     * 参数:currentPage=x
     **/
    @GetMapping("/listAll")
    public Object GetListAll(QueryObject qo){
        return productService.query(qo);
    }






    /*
     *查询对应id的商品内容,批量查询
     * 资源:/products
     * 动作:GET
     * 参数:currentPage=x
     **/
    @GetMapping("/list")
    public Object GetProductByIds(Long[] ids){
        return productService.bathchGetList(ids);
    }







    //局部分页太难了
    /*
     *查询对应id的商品内容,批量查询
     * 资源:/products
     * 动作:GET
     * 参数:currentPage=x
     **/
    @GetMapping
    public Object GetProductByIds(Long[] ids,QueryObject qo){
        return productService.bathchGet(ids,qo);
    }




    /*
     * 查询一周内的商品
     * 资源:/products/week
     * 动作:get
     * 参数:
     * */
    @GetMapping("/week")
    public Object getProductsByWeek(QueryObject qo){
        return productService.selectByDate(qo);
    }




    /*
     * 根据对应id的商品
     * 资源:/products/{id}
     * 动作:get
     * 参数:
     * */
    @GetMapping("/{id}")
    public Object getProductsById(@PathVariable Long id){
        return productService.selectById(id);
    }



    /*
     * 根据某个商品下的详情内容
     * 资源:/products/details/{id}
     * 动作:get
     * 参数:
     * */
    @GetMapping("/particulars/{id}")
    public Object getParticularsById(@PathVariable Long id){
        return "";
    }
}
